package com.whx.managea.controller;


import com.whx.managea.entity.City;
import com.whx.managea.entity.Tag;
import com.whx.managea.service.CityService;
import com.whx.managea.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("tag")
public class TagController {

    @Autowired
    private TagService tagService;

    //定义用来接受查询所有的请求
    @RequestMapping("findAll")
    public String findAll(Model model){
        //1.调用业务层查询所有的标签
        List<Tag> tags = tagService.findAll();
        //2.把查询到的所有的城市设置在域中
        model.addAttribute("tags", tags);
        return "back/tag/index";

    }

    //定义一个用来接受添加标签的请求
    @RequestMapping("save")
    public String save(Tag tag){
        tagService.save(tag);
        //重新跳转到显示所有标签的页面

        return "redirect:/tag/findAll";
    }

    //定义一个用来接受查询指定类型的标签集合
    @RequestMapping("findByType")
    @ResponseBody
    public List<Tag> findByType(String type){
        return tagService.findByType(type);
    }
}
